Repository navigation
pm-stack(external-comms): quarantine malformed pusher outbox lines (#6154) - #6199
Conversation
do_push silently dropped outbox lines it could not parse: the line never reached pending, the outbox rewrite deleted it, and health could still report a clean drain — destroying the only fallback copy of a send record (issue #6154). - Unparseable / non-object lines are appended verbatim to quarantine.jsonl in the state dir (raw line + timestamp + reason, fsync) before the outbox rewrite removes them; if the quarantine write fails the raw line stays in the outbox. - pusher-health.json gains last_run_quarantined, total_quarantined, last_quarantine_at/reason and last_lossy_drain_at; a run that quarantined a line clears last_drain_ok_at instead of claiming a clean drain. The stdout summary reports the quarantined count (never record contents). - Valid records keep their insert / ignore-duplicates / retry bookkeeping exactly as before. - test_push_quarantine.py pins torn-only, mixed valid+torn, valid-only control and non-object cases against the real script with an isolated state dir and a loopback-refused DB. Fixes #6154
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 27 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41c84f53f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| with open(QUARANTINE, "a") as f: | ||
| f.write(json.dumps(entry) + "\n") | ||
| f.flush() | ||
| os.fsync(f.fileno()) |
There was a problem hiding this comment.
Recover partial quarantine appends before retrying
If a quarantine append fails after writing a prefix (for example, when the disk fills), that prefix remains in quarantine.jsonl while the original line stays pending. Once space is available, the next run appends a complete entry directly after the unterminated prefix, counts it as successfully quarantined, and removes the original from the outbox. The resulting line is invalid JSON, so ordinary JSONL recovery cannot recover that record. Roll back failed appends to their starting offset, or repair an incomplete trailing entry before appending another record.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the follow-up commit (quarantine rollback): quarantine_line now records the starting offset of quarantine.jsonl before appending and, on any append failure (write/flush/fsync), truncates the file back to that offset before re-raising — so no unterminated prefix can merge with the next entry, and the caller keeps the raw line in the outbox (pending_raw) for the next run. Pinned by QuarantineRollbackCase.test_failed_append_rolls_back_to_starting_offset, which simulates an fsync failure mid-append, asserts the file is byte-identical afterwards, and asserts the next successful append parses as a clean JSONL entry. — task 10006, lane code-y
| def test_torn_only_is_quarantined_and_not_a_clean_drain(self): | ||
| summary, health, quarantine, outbox = self.run_push([TORN]) |
There was a problem hiding this comment.
Add generated coverage for the quarantine invariant
The new parser/quarantine behavior has a meaningful conservation invariant—each nonblank input must remain pending or survive verbatim in quarantine—but this suite exercises only four hand-written examples. Root AGENTS.md explicitly requires property tests for parser invariants and states that example-based tests do not replace them. Add generated malformed/non-object lines and mixed batches that assert preservation and the corresponding pending/quarantine counts.
AGENTS.md reference: AGENTS.md:L41-L45
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the follow-up commit: added GeneratedConservationCase.test_generated_mixed_batches_preserve_every_line — a seeded generated test (120 mixed lines: valid records, truncated-JSON prefixes, non-object JSON values, garbage) whose oracle is exactly the conservation invariant you name: every nonblank input line ends the run pending in the outbox or preserved verbatim in quarantine, with summary/health counts matching (quarantined + pending == total lines, total_quarantined == generated malformed count, valid ids each pending once with retry bookkeeping). 6/6 tests pass on the laptop. — task 10006, lane code-y
…ated conservation tests Codex review on PR #6199, both findings fixed: - P2: a quarantine append failing mid-write left an unterminated prefix in quarantine.jsonl; the next entry merged with it into an invalid JSON line and the record became unrecoverable despite counting as quarantined. quarantine_line now records the starting offset and truncates back to it on any append failure before re-raising (the raw line stays in the outbox via pending_raw). - P1: the suite was example-only. Added a generated conservation test (seeded, 120 mixed lines: valid, truncated-JSON, non-object JSON, garbage) whose oracle is the invariant that every nonblank line ends the run pending or verbatim in quarantine, with counts to match; plus a rollback test that simulates an fsync failure mid-append. 6/6 tests pass on the laptop.
Fixes #6154
Problem
record-external-send pushsilently dropped outbox lines it could not parse (do_push:except: continue). The line never reachedpending, so the outbox rewrite deleted it permanently — whilepusher-health.jsonand stdout could still report a clean drain (last_drain_ok_atset,pending: 0,last_error: null). The outbox is the fallback copy of a send record; a torn/corrupt line (crash mid-append, disk-full truncation, operator edit) vanished with an affirmative success report, against this module's own NEVER SILENT rule.Change
quarantine.jsonlin the state dir — exact raw line +_quarantined_at+_reason, fsync'd — before the outbox rewrite removes them. If the quarantine write itself fails, the raw line stays in the outbox for the next run.pusher-health.jsongainslast_run_quarantined,total_quarantined,last_quarantine_at,last_quarantine_reason, andlast_lossy_drain_at; a run that quarantined a line clearslast_drain_ok_atinstead of claiming a clean drain."quarantined": <count>(counts only, never record contents)._attempts/_last_errorretry bookkeeping exactly as before.Tests (laptop, real script, isolated state dir, loopback-refused DB)
New
pm-stack/external-comms/test_push_quarantine.py— 4/4 pass:quarantine.jsonl, health counts it, nolast_drain_ok_at[1, 2]): quarantined with reasonnot a JSON objectPlus a manual mixed probe: stdout
quarantined: 1, healthtotal_quarantined: 1with reason, outbox keeps only the valid record with_attempts: 1.Queue: task 10006 (repo-health-code-pilot), lane code-y.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.